

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>


<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/avatar2.jpg">
  <link rel="icon" href="/img/avatar2.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="李延胜">
  <meta name="keywords" content="">
  
    <meta name="description" content="​    本次课程设计时间大概是两天半，磕磕碰碰，一路上遇到了很多的问题，也不断的查资料，想办法解决各种拦路的BUG，最后做出来的效果自己还是挺满意的，能够实现多台电脑之间模拟服务端，客户端，进行文件传送。下面做一下整理（附程序和运行效果截图）  课程设计任务（1）学习TCP&#x2F;IP网络基本知识，学习socket通信基本知识，设计基于Socket的网络通信程序，在LINUX 系统与WIN">
<meta property="og:type" content="article">
<meta property="og:title" content="嵌入式课程设计">
<meta property="og:url" content="http://example.com/posts/22685.html">
<meta property="og:site_name" content="liyansheng_blog">
<meta property="og:description" content="​    本次课程设计时间大概是两天半，磕磕碰碰，一路上遇到了很多的问题，也不断的查资料，想办法解决各种拦路的BUG，最后做出来的效果自己还是挺满意的，能够实现多台电脑之间模拟服务端，客户端，进行文件传送。下面做一下整理（附程序和运行效果截图）  课程设计任务（1）学习TCP&#x2F;IP网络基本知识，学习socket通信基本知识，设计基于Socket的网络通信程序，在LINUX 系统与WIN">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/202107101338392.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20210710134126112.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20210710134313954.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20210710134716335.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/202107101333472.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20210710135309723.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="http://liyansheng.top/typora/pvTQ1bYb9j2rLQe0WQEfmAqnbxLhUfje.gif">
<meta property="article:published_time" content="2023-06-01T11:26:00.000Z">
<meta property="article:modified_time" content="2024-04-28T16:25:54.667Z">
<meta property="article:author" content="李延胜">
<meta property="article:tag" content="作品">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/202107101338392.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>嵌入式课程设计 - liyansheng_blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":50,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":"85b00ecca8bd5efa8a581f758ba73a03","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?85b00ecca8bd5efa8a581f758ba73a03";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>木子-博客</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>作者</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/remote_help/">
                
                <span>🐞远程调试/功能定做</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tool/">
                
                <span>💪利其器</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/HTML/ai-chat.html">
                <i class="iconfont icon-bot"></i>
                <span>🤖Ai助手</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/bg5.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="嵌入式课程设计"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-06-01 19:26" pubdate>
          2023年6月1日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.9k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          49 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">嵌入式课程设计</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：18 分钟前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <blockquote>
<p>​    <strong>本次课程设计时间大概是两天半，磕磕碰碰，一路上遇到了很多的问题，也不断的查资料，想办法解决各种拦路的BUG，最后做出来的效果自己还是挺满意的，能够实现多台电脑之间模拟服务端，客户端，进行文件传送。下面做一下整理（附程序和运行效果截图）</strong></p>
</blockquote>
<h2 id="课程设计任务"><a href="#课程设计任务" class="headerlink" title="课程设计任务"></a>课程设计任务</h2><p>（1）学习TCP&#x2F;IP网络基本知识，学习socket通信基本知识，设计基于Socket的网络通信程序，在LINUX 系统与WINDOWS系统之间进行通信，使用C++语言实现。</p>
<p>（2）在Socket服务端，能够读出一副图像数据，经过网络通信，自己设计协议，将这副图片发送到客户端，客户端接收到这副图片后，将其显示在屏幕上。</p>
<h2 id="程序代码"><a href="#程序代码" class="headerlink" title="程序代码"></a>程序代码</h2><p><code>PS</code>：程序代码并不多，这里直接贴出来了。主要是用C++语言实现的，感兴趣的伙伴可以直接粘贴到VS试一下。</p>
<h3 id="服务端程序"><a href="#服务端程序" class="headerlink" title="服务端程序"></a><strong>服务端程序</strong></h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-meta">#<span class="hljs-keyword">include</span><span class="hljs-string">&lt;iostream&gt;</span></span><br><span class="hljs-comment">//#include&lt;winsock.h&gt;</span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;winsock2.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span><span class="hljs-string">&lt;stdio.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span><span class="hljs-string">&lt;stdlib.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">pragma</span> comment(lib,<span class="hljs-string">&quot;ws2_32.lib&quot;</span>)</span><br><span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> std;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">initialization</span><span class="hljs-params">()</span></span>;<br><span class="hljs-meta">#<span class="hljs-keyword">define</span> BUF_SIZE 1024</span><br>SOCKET s_accept;<br>SOCKADDR_IN accept_addr;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">sendFile</span><span class="hljs-params">()</span> </span>&#123;<br>	cout &lt;&lt; <span class="hljs-string">&quot;输入待传送的文件名：&quot;</span>;<br>	<span class="hljs-type">char</span> filename1[<span class="hljs-number">100</span>];<br>	cin &gt;&gt; filename1;<br>	<span class="hljs-comment">//检查文件是否存在</span><br>	<span class="hljs-type">const</span> <span class="hljs-type">char</span> *filename = filename1;<br><span class="hljs-meta">#<span class="hljs-keyword">pragma</span> <span class="hljs-keyword">warning</span>(suppress : 4996)</span><br>	FILE *fp = <span class="hljs-built_in">fopen</span>(filename, <span class="hljs-string">&quot;rb&quot;</span>);<br>	<span class="hljs-keyword">if</span> (fp == <span class="hljs-literal">NULL</span>)<br>	&#123;<br>		<span class="hljs-built_in">printf</span>(<span class="hljs-string">&quot;不能打开文件，按任何键退出！&quot;</span>);<br>		<span class="hljs-built_in">system</span>(<span class="hljs-string">&quot;pause&quot;</span>);<br>		<br>	&#125;<br>	<span class="hljs-keyword">else</span><br>	&#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;文件准备就绪&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	<span class="hljs-comment">//循环发送数据，直到文件结尾</span><br>	<span class="hljs-type">char</span> buffer[BUF_SIZE] = &#123; <span class="hljs-number">0</span> &#125;;<span class="hljs-comment">//缓冲区</span><br>	<span class="hljs-type">int</span> nCount;<br>	<span class="hljs-keyword">while</span> ((nCount = <span class="hljs-built_in">fread</span>(buffer, <span class="hljs-number">1</span>, BUF_SIZE, fp)) &gt; <span class="hljs-number">0</span>)<br>	&#123;<br>		<span class="hljs-built_in">send</span>(s_accept, buffer, nCount, <span class="hljs-number">0</span>);<br>	&#125;<br>	<span class="hljs-built_in">shutdown</span>(s_accept, SD_SEND);文件读取完毕，断开输出流，向客户端发送FIN包,注意加头文件<span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&lt;winsock2.h&gt;</span>，不然报错</span><br>	<span class="hljs-built_in">recv</span>(s_accept, buffer, BUF_SIZE, <span class="hljs-number">0</span>);<span class="hljs-comment">//阻塞，等待客户端接收完毕</span><br>	<span class="hljs-comment">//关闭文件</span><br>	<span class="hljs-built_in">fclose</span>(fp);<br>&#125;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">listen1</span><span class="hljs-params">(SOCKET s_server,<span class="hljs-type">int</span> len, SOCKADDR_IN accept_addr)</span> </span>&#123;<br>	<span class="hljs-comment">//设置套接字为监听状态</span><br>	<span class="hljs-keyword">if</span> (<span class="hljs-built_in">listen</span>(s_server, SOMAXCONN) &lt; <span class="hljs-number">0</span>) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;设置监听状态失败！&quot;</span> &lt;&lt; endl;<br>		<span class="hljs-built_in">WSACleanup</span>();<br>	&#125;<br>	<span class="hljs-keyword">else</span> &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;设置监听状态成功！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	cout &lt;&lt; <span class="hljs-string">&quot;服务端正在监听连接，请稍候....&quot;</span> &lt;&lt; endl;<br>	cout &lt;&lt; <span class="hljs-string">&quot;-------------------------------------&quot;</span> &lt;&lt; endl;<br>	<span class="hljs-comment">//接受连接请求</span><br>	len = <span class="hljs-built_in">sizeof</span>(SOCKADDR);<br>	s_accept = <span class="hljs-built_in">accept</span>(s_server, (SOCKADDR*)&amp;accept_addr, &amp;len);<br>	<span class="hljs-keyword">if</span> (s_accept == SOCKET_ERROR) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;连接失败！&quot;</span> &lt;&lt; endl;<br>		<span class="hljs-built_in">WSACleanup</span>();<br>	&#125;<br>	cout &lt;&lt; <span class="hljs-string">&quot;连接就绪~&quot;</span> &lt;&lt; endl;<br>&#125;<br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>&#123;<br>	<span class="hljs-comment">//定义长度变量</span><br>	<span class="hljs-type">int</span> len = <span class="hljs-number">0</span>;<br>	<span class="hljs-comment">//定义服务端套接字，接受请求套接字</span><br>	SOCKET s_server;<br>	<span class="hljs-comment">//服务端地址客户端地址</span><br>	SOCKADDR_IN server_addr;<br>	<span class="hljs-built_in">initialization</span>();<br>	<span class="hljs-comment">//填充服务端信息</span><br>	server_addr.sin_family = AF_INET;<br>	server_addr.sin_addr.S_un.S_addr = <span class="hljs-built_in">htonl</span>(INADDR_ANY);<br>	<span class="hljs-comment">//设置端口号</span><br>	server_addr.sin_port = <span class="hljs-built_in">htons</span>(<span class="hljs-number">1234</span>);<br>	<span class="hljs-comment">//创建套接字</span><br>	s_server = <span class="hljs-built_in">socket</span>(AF_INET, SOCK_STREAM, <span class="hljs-number">0</span>);<br>	<span class="hljs-comment">//绑定套接字到一个IP地址和一个端口上</span><br>	<span class="hljs-keyword">if</span> (<span class="hljs-built_in">bind</span>(s_server, (SOCKADDR*)&amp;server_addr, <span class="hljs-built_in">sizeof</span>(SOCKADDR)) == SOCKET_ERROR) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;-----------------------------&quot;</span> &lt;&lt; endl;<br>		cout &lt;&lt; <span class="hljs-string">&quot;套接字绑定失败！&quot;</span> &lt;&lt; endl;<br>		<span class="hljs-built_in">WSACleanup</span>();<br>	&#125;<br>	<span class="hljs-keyword">else</span> &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;套接字绑定成功！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	<span class="hljs-comment">//监听</span><br>	<span class="hljs-built_in">listen1</span>(s_server, len, accept_addr);<br>	<span class="hljs-comment">//发送文件</span><br>	<span class="hljs-keyword">while</span> (<span class="hljs-literal">true</span>)<br>	&#123;<br>		<span class="hljs-built_in">sendFile</span>();<br>	&#125;<br>	<span class="hljs-comment">//关闭套接字</span><br>	<span class="hljs-built_in">closesocket</span>(s_server);<br>	<span class="hljs-built_in">closesocket</span>(s_accept);<br>	<span class="hljs-comment">//释放DLL资源</span><br>	<span class="hljs-built_in">WSACleanup</span>();<br>	<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">initialization</span><span class="hljs-params">()</span> </span>&#123;<br>	<span class="hljs-comment">//初始化套接字库</span><br>	WORD w_req = <span class="hljs-built_in">MAKEWORD</span>(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>);<span class="hljs-comment">//版本号</span><br>	WSADATA wsadata;<br>	<span class="hljs-type">int</span> err;<br>	err = <span class="hljs-built_in">WSAStartup</span>(w_req, &amp;wsadata);<br>	<span class="hljs-keyword">if</span> (err != <span class="hljs-number">0</span>) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;初始化套接字库失败！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	<span class="hljs-keyword">else</span> &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;初始化套接字库成功！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="客户端程序"><a href="#客户端程序" class="headerlink" title="客户端程序"></a><strong>客户端程序</strong></h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-meta">#<span class="hljs-keyword">include</span><span class="hljs-string">&lt;iostream&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">include</span><span class="hljs-string">&lt;winsock.h&gt;</span></span><br><span class="hljs-meta">#<span class="hljs-keyword">pragma</span> comment(lib,<span class="hljs-string">&quot;ws2_32.lib&quot;</span>)</span><br><span class="hljs-keyword">using</span> <span class="hljs-keyword">namespace</span> std;<br><span class="hljs-meta">#<span class="hljs-keyword">define</span> BUF_SIZE 1024</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">initialization</span><span class="hljs-params">()</span></span>;<br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>&#123;<br>	<span class="hljs-comment">//定义服务端套接字，接受请求套接字</span><br>	SOCKET s_server;<br>	<span class="hljs-comment">//服务端地址客户端地址</span><br>	SOCKADDR_IN server_addr;<br>	<span class="hljs-built_in">initialization</span>();<br>	<span class="hljs-comment">//填充服务端信息</span><br>	server_addr.sin_family = AF_INET;<br>	<span class="hljs-comment">//获取IP</span><br>	cout &lt;&lt; <span class="hljs-string">&quot;-------------------------&quot;</span> &lt;&lt; endl;<br>	cout &lt;&lt; <span class="hljs-string">&quot;输入服务器的IP：&quot;</span>;<br>	<span class="hljs-comment">//定义保存输入IP的字符数组</span><br>	<span class="hljs-type">char</span> Service_ip[<span class="hljs-number">15</span>];<br>	<span class="hljs-comment">//遇到空格或者回车结束输入</span><br>	cin &gt;&gt; Service_ip;<br>	server_addr.sin_addr.S_un.S_addr = <span class="hljs-built_in">inet_addr</span>(Service_ip);<br>	<span class="hljs-comment">//server_addr.sin_addr.S_un.S_addr = inet_addr(&quot;127.0.0.1&quot;);</span><br>	server_addr.sin_port = <span class="hljs-built_in">htons</span>(<span class="hljs-number">1234</span>);<br>	<span class="hljs-comment">//创建套接字</span><br>	s_server = <span class="hljs-built_in">socket</span>(AF_INET, SOCK_STREAM, <span class="hljs-number">0</span>);<br>	<span class="hljs-keyword">if</span> (<span class="hljs-built_in">connect</span>(s_server, (SOCKADDR*)&amp;server_addr, <span class="hljs-built_in">sizeof</span>(SOCKADDR)) == SOCKET_ERROR) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;服务器连接失败！&quot;</span> &lt;&lt; endl;<br>		<span class="hljs-built_in">WSACleanup</span>();<br>		<span class="hljs-built_in">WSACleanup</span>();<br>	&#125;<br>	<span class="hljs-keyword">else</span> &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;服务器连接成功！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	<span class="hljs-keyword">while</span> (<span class="hljs-number">1</span>)<br>	&#123;<br>		<span class="hljs-comment">//输入文件名，看文件能否创建成功</span><br>		<span class="hljs-type">char</span> filename[<span class="hljs-number">100</span>] = &#123; <span class="hljs-number">0</span> &#125;;<br>		cout &lt;&lt; <span class="hljs-string">&quot;请输入要保存的文件：&quot;</span>;<br>		cin &gt;&gt; filename;<br>		<span class="hljs-comment">//以二进制创建文件</span><br><span class="hljs-meta">#<span class="hljs-keyword">pragma</span> <span class="hljs-keyword">warning</span>(suppress : 4996)</span><br>		FILE *fp = <span class="hljs-built_in">fopen</span>(filename, <span class="hljs-string">&quot;wb&quot;</span>);<span class="hljs-comment">//以只写方式打开或新建一个二进制文件，只允许写数据</span><br>		<span class="hljs-comment">//循环接受</span><br>		<span class="hljs-type">char</span> buffer[BUF_SIZE] = &#123; <span class="hljs-number">0</span> &#125;;<span class="hljs-comment">//文件保存缓冲区</span><br>		<span class="hljs-type">int</span> nCount = <span class="hljs-number">0</span>;<br>		<span class="hljs-keyword">while</span> ((nCount = <span class="hljs-built_in">recv</span>(s_server, buffer, BUF_SIZE, <span class="hljs-number">0</span>)) &gt; <span class="hljs-number">0</span>)<span class="hljs-comment">//recv(对应的套接字，保存数据的地方，保存区的大小，第四个参数一般设置为 0</span><br>		&#123;<br>			<span class="hljs-built_in">fwrite</span>(buffer, nCount, <span class="hljs-number">1</span>, fp);<span class="hljs-comment">//buffer输出数据的地址，nCount要输入内容的字节数，1位写入nCount字节的数据项的个数,fp为目标文件</span><br>		&#125;<br>		<span class="hljs-keyword">if</span> (fp == <span class="hljs-literal">NULL</span>)<br>		&#123;<br>			cout &lt;&lt; <span class="hljs-string">&quot;接收文件失败!&quot;</span>;<br>			<span class="hljs-built_in">system</span>(<span class="hljs-string">&quot;pause&quot;</span>);<br>			<span class="hljs-built_in">exit</span>(<span class="hljs-number">0</span>);<br>		&#125;<br>		<span class="hljs-keyword">if</span> (fp != <span class="hljs-literal">NULL</span>) &#123;<br>			cout &lt;&lt; <span class="hljs-string">&quot;文件接收成功！&quot;</span> &lt;&lt; endl;<br>		&#125;<br>		<span class="hljs-comment">//打开并显示图片</span><br>		<span class="hljs-built_in">ShellExecute</span>(<span class="hljs-literal">NULL</span>,<span class="hljs-string">&quot;open&quot;</span>, filename, <span class="hljs-literal">NULL</span>, <span class="hljs-literal">NULL</span>, SW_SHOWNORMAL);<br>		<span class="hljs-built_in">system</span>(<span class="hljs-string">&quot;pause&quot;</span>);<br>		<span class="hljs-built_in">fclose</span>(fp);<br>	&#125;<br>	<span class="hljs-comment">//关闭套接字</span><br>	<span class="hljs-built_in">closesocket</span>(s_server);<br>	<span class="hljs-comment">//释放DLL资源</span><br>	<span class="hljs-built_in">WSACleanup</span>();<br>	<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">initialization</span><span class="hljs-params">()</span> </span>&#123;<br>	<span class="hljs-comment">//初始化套接字库</span><br>	WORD w_req = <span class="hljs-built_in">MAKEWORD</span>(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>);<span class="hljs-comment">//版本号</span><br>	WSADATA wsadata;<br>	<span class="hljs-type">int</span> err;<br>	err = <span class="hljs-built_in">WSAStartup</span>(w_req, &amp;wsadata);<br>	<br>	<span class="hljs-comment">//检测版本号</span><br>	<span class="hljs-keyword">if</span> (<span class="hljs-built_in">LOBYTE</span>(wsadata.wVersion) != <span class="hljs-number">2</span> || <span class="hljs-built_in">HIBYTE</span>(wsadata.wHighVersion) != <span class="hljs-number">2</span>) &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;套接字库版本号不符！&quot;</span> &lt;&lt; endl;<br>		<span class="hljs-built_in">WSACleanup</span>();<br>	&#125;<br>	<span class="hljs-keyword">else</span> &#123;<br>		cout &lt;&lt; <span class="hljs-string">&quot;套接字库版本正确！&quot;</span> &lt;&lt; endl;<br>	&#125;<br>	<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h2><p><code>PS</code>：分别运行服务端和客户端，本机测试IP地址用127.0.0.1，局域网的话IP自己查IPv4对应的IP号（这里用本机回环测试演示）</p>
<p><img src="https://img-blog.csdnimg.cn/202107101338392.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload></p>
<p>在客户端输入IP，然后回车可以看到连接是否成功</p>
<p><img src="https://img-blog.csdnimg.cn/20210710134126112.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload></p>
<p> 然后在服务端输入要传送的文件的路径：（这里演示传送一个视频,发送图片的方式也同理）</p>
<p><img src="https://img-blog.csdnimg.cn/20210710134313954.png" srcset="/img/loading.gif" lazyload></p>
<p> 在客户端也输入要保存服务端传送过来文件的地址，保存在哪里可以自己定义，文件名也可以自己定义，但是文件格式一定要跟服务器传过来的文件的文件格式一致，即文件后缀名要一样</p>
<p><img src="https://img-blog.csdnimg.cn/20210710134716335.png" srcset="/img/loading.gif" lazyload></p>
<p> 文件传送成功后，程序会自动调用计算机的默认应用打开文件，即你是传送的文件，那么你收到文件后，系统会调用计算机的视频播放软件打开，如果是图片，那么就会用图片查看器打开，其他文件格式也同理</p>
<p><img src="https://img-blog.csdnimg.cn/202107101333472.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload></p>
<p> 打开刚刚保存文件的路径，可以看到我们的文件传送过来了，两个文件大小一致</p>
<p><img src="https://img-blog.csdnimg.cn/20210710135309723.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDEwNzE0MA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload></p>
<p><strong>不同计算机连接同一个局域网也能实现文件传送呢，感兴趣的伙伴可以试一下哦！！</strong></p>
<h2 id="不足之处"><a href="#不足之处" class="headerlink" title="不足之处"></a>不足之处</h2><p>一次运行只能传输一次文件，然后程序就结束退出了，需要再一次传送文件还得再重新先打开服务端然后打开客户端连接， 这个可以考虑把发送接收文件的代码块放到一个循环里，我今天简单尝试了一下，没有成功，时间问题，就没来得及继续完善这个不足了，感兴趣的伙伴可以把上面程序修改修改试试。</p>
<hr>
<p>本期内容分享到这！！ 下期见！！！</p>
<p>  <img src="http://liyansheng.top/typora/pvTQ1bYb9j2rLQe0WQEfmAqnbxLhUfje.gif" srcset="/img/loading.gif" lazyload></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E4%BD%9C%E5%93%81/" class="category-chain-item">作品</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E4%BD%9C%E5%93%81/">#作品</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>嵌入式课程设计</div>
      <div>http://example.com/posts/22685.html</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>李延胜</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年6月1日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/posts/8266.html" title="计算机网络课程设计-在线聊天室设计">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">计算机网络课程设计-在线聊天室设计</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/posts/28882.html" title="MySQL修改密码与设置字符编码集">
                        <span class="hidden-mobile">MySQL修改密码与设置字符编码集</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"SabYreKdzdOiQemY4H7Pzbjr-gzGzoHsz","appKey":"o5EFclbNb5gGIxPipHHkBfg2","path":"window.location.pathname","placeholder":"您想说点什么吗...","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://blog.csdn.net/weixin_44107140" target="_blank" rel="nofollow noopener"> <span>CSDN博客</span></a> <i class="iconfont">|</i> <a href="https://gitee.com/yan-sheng-li" target="_blank" rel="nofollow noopener"><span>Gitee码云</span></a> <i class="iconfont">|</i> <a href="#" target="_blank" rel="nofollow noopener"><span style="color:green">微信公众号：《编程亿点有趣》</span></a> <i class="iconfont">|</i><a target="_blank" href="https://qm.qq.com/cgi-bin/qm/qr?k=NZUoWMzd3PQLWwxRGMiBNYEnVkEdNq__&jump_from=webapi&authKey=kgAofDqUzgwMCSX+UQQwxf837zMeWFGGmo4iIcbgkklW2pdfmVOlxPWAK6sMYMaC"> <img border="0" src="../../img/group.png" srcset="/img/loading.gif" lazyload alt="远程调试-学习交流" title="远程调试-学习交流"></a>
    </div>
  
  
    <div class="statistics">
  
  

  
    
    
    
  
</div>

  
  
  

  <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=298 height=52 src="//music.163.com/outchain/player?type=2&id=2031204435&auto=1&height=32"></iframe>

</div>


  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"hHeadPos":0.5,"vHeadPos":0.618,"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"superSample":1,"width":200,"height":300,"position":"left","hOffset":0,"vOffset":-50},"mobile":{"show":true,"scale":0.5},"react":{"opacityDefault":0.7,"opacityOnHover":0.8},"log":false});</script></body>
</html>
